Automated refactoring to the Strategy design pattern
نویسندگان
چکیده
Context: The automated identification of code fragments characterized by common design flaws (or ‘‘code smells’’) that can be handled through refactoring, fosters refactoring activities, especially in large code bases where multiple developers are engaged without a detailed view on the whole system. Automated refactoring to design patterns enables significant contributions to design quality even from developers with little experience on the use of the required patterns. Objective: This work targets the automated identification of refactoring opportunities to the Strategy design pattern and the elimination through polymorphism of respective ‘‘code smells’’ that are related to extensive use of complex conditional statements. Method: An algorithm is introduced for the automated identification of refactoring opportunities to the Strategy design pattern. Suggested refactorings comprise conditional statements that are characterized by analogies to the Strategy design pattern, in terms of the purpose and selection mode of strategies. Moreover, this work specifies the procedure for refactoring to Strategy the identified conditional statements. For special cases of these statements, a technique is proposed for total replacement of conditional logic with method calls of appropriate concrete Strategy instances. The identification algorithm and the refactoring procedure are implemented and integrated in the JDeodorant Eclipse plug-in. The method is evaluated on a set of Java projects, in terms of quality of the suggested refactorings and run-time efficiency. The relevance of the identified refactoring opportunities is verified by expert software engineers. Results: The identification algorithm recalled, from the projects used during evaluation, many of the refactoring candidates that were identified by the expert software engineers. Its execution time on projects of varying size confirmed the run-time efficiency of this method. Conclusion: The proposed method for automated refactoring to Strategy contributes to simplification of conditional statements. Moreover, it enhances system extensibility through the Strategy design pattern. 2012 Elsevier B.V. All rights reserved.
منابع مشابه
An Automated Refactoring Approach to Design Pattern-Based Program Transformations in Java Programs
Software often needs to be modified for accommodating requirements changes through the software life cycle. To deal with several accidental requirements changes related to software maintenance, a systematic and safe approach to modifying softwares is needed. The design patterns provide a high degree of design flexibility for such accidental requirements changes. In this paper, we propose an aut...
متن کاملRefactoringScript: A Script and Its Processor for Composite Refactoring
Refactoring is widely recognized as a method to improve the internal qualities of source code. However, manual refactoring is time-consuming and error-prone. Consequently, many tools to support automated refactoring have been suggested, but most support only unit and simple refactoring, making it difficult to perform composite refactoring (e.g., introducing a design pattern) where a refactoring...
متن کاملAutomated refactoring to the Null Object design pattern
Context: Null-checking conditionals are a straightforward solution against null dereferences. However, their frequent repetition is considered a sign of poor program design, since they introduce source code duplication and complexity that impacts code comprehension and maintenance. The Null Object design pattern enables the replacement of null-checking conditionals with polymorphic method invoc...
متن کاملMORE: A multi-objective refactoring recommendation approach to introducing design patterns and fixing code smells
Refactoring is widely recognized as a crucial technique applied when evolving object-oriented software systems. If applied well, refactoring can improve different aspects of software quality including readability, maintainability and extendibility. However, despite its importance and benefits, recent studies report that automated refactoring tools are underused much of the time by software deve...
متن کاملInferring design patterns using the ReP graph
Periodic refactoring of a large source code often becomes a necessity especially for long-lived projects. In order to increase maintainability and extensibility of such projects, design pattern based refactoring can be seen as an emerging alternative. Manual inspection of source code to find candidate spots where patterns can be introduced is time consuming. Therefore automated tools can help i...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
- Information & Software Technology
دوره 54 شماره
صفحات -
تاریخ انتشار 2012